﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;

using ERPStore.Extensions;

namespace ERPStore.Exporter.Reporting.Controllers
{
    public class ReportsController : ERPStore.Web.Controllers.StoreController
    {
        public ReportsController(Services.ReportService reportService)
        {
            this.ReportService = reportService;
        }

        protected Services.ReportService ReportService { get; private set; }

		public ActionResult Index()
		{
			return new ContentResult()
			{
				Content = DateTime.Now.ToString(),
				ContentType = "text/plain",
			};
		}

        [ERPStore.Web.Controllers.ActionFilters.TrackerActionFilter]
        public ActionResult OrderCartReport(string id, string format)
        {
            string fileName = null;
            string mimeType = null;
            var content = ReportService.GetOrderCartReportByCode(id, out fileName, out mimeType, User, format);
            if (content == null)
            {
                return new EmptyResult();
            }
			Response.AddHeader("content-disposition", string.Format("attachement; filename={0}", fileName));
			Response.Charset = "";
			Response.Cache.SetCacheability(HttpCacheability.NoCache);
			return this.File(content, mimeType);
        }
    }
}
